package com.fho4565.commands;

import com.fho4565.main.Utils;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;

import java.util.UUID;
public class UUIDCommand {
    private static boolean allowed;
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
        dispatcher.register(
                Commands.literal("uuid")
                        .then(Commands.literal("allowToUse").requires(s->s.hasPermission(2))
                                .then(Commands.argument("allow", BoolArgumentType.bool())
                                .executes(context -> {
                                    allowed = BoolArgumentType.getBool(context, "allow");
                                    return 1;
                                })))
                        .then(Commands.argument("playerName", EntityArgument.player())
                                .executes(context -> {
                                    if(allowed){
                                        UUID uuid = EntityArgument.getPlayer(context, "playerName").getGameProfile().getId();
                                        Utils.sendCdFeedback(context, uuid.toString(),true);
                                    }else{
                                        Utils.sendCdFeedback(context, UUID.randomUUID().toString());
                                    }
                                    return 1;
                                }))
        );
    }
}
